package com.catalog.Shapes
{
	import Util.DrawShapeUtil;
	
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import mx.core.UIComponent;
	import mx.graphics.GradientBase;
	
	[Style(name="borderColor",type="uint")]
	
	[Style(name="fillColor",type="uint")]
	
	public class GearSprite extends UIComponent
	{
		private var _gear:Sprite;
		
		public function GearSprite()
		{
			super();
		}
		
		private var _side:int=10;

		public function get side():int
		{
			return _side;
		}

		public function set side(value:int):void
		{
			_side = value;
		}

		
		private var _innerRadius:int=10;

		public function get innerRadius():int
		{
			return _innerRadius;
		}

		public function set innerRadius(value:int):void
		{
			_innerRadius = value;
		}

		
		private var _outRadius:int=15;

		public function get outRadius():int
		{
			return _outRadius;
		}

		public function set outRadius(value:int):void
		{
			_outRadius = value;
		}

		
		private var _angleNumer:Number=0;

		public function get angleNumer():Number
		{
			return _angleNumer;
		}

		public function set angleNumer(value:Number):void
		{
			_angleNumer = value;
		}

		
		private var _holeSides:int=5;

		public function get holeSides():int
		{
			return _holeSides;
		}

		public function set holeSides(value:int):void
		{
			_holeSides = value;
		}

		
		private var _holeRadius:int=5;

		public function get holeRadius():int
		{
			return _holeRadius;
		}

		public function set holeRadius(value:int):void
		{
			_holeRadius = value;
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			_gear = new Sprite();
			addChild( _gear );
		}
		
		override protected function measure():void
		{
			measuredHeight = measuredMinHeight = 22;
			measuredWidth = measuredMinWidth = 22;
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList( unscaledWidth,unscaledHeight );
			var borderColor:uint = getStyle("borderColor");
			var fillColor:uint = getStyle("fillColor");
			var g:Graphics = _gear.graphics;
			g.lineStyle(1,borderColor);
			g.beginFill(fillColor);
			DrawShapeUtil.drawGear(g,unscaledWidth/2,unscaledHeight/2,side,innerRadius,outRadius,angleNumer,holeSides,holeRadius);
			g.endFill();
		}
	}
}